//
//  DPWalletFlowDetailViewController.swift
//  DoctorEPlus
//
//  Created by 王林波 on 2021/3/8.
//  账单详情

import UIKit

class DPWalletFlowDetailViewController: BHBaseViewController {

    lazy var tableView: UITableView = {
        let view = UITableView.buildTableView(style: .plain)
        
        view.frame = CGRect(x: 0, y: UIScreen.begainY, width: UIScreen.width, height: UIScreen.showHeight)
        view.register(UINib.init(nibName: "DPWalletFlowDetailCell", bundle: nil), forCellReuseIdentifier: "DPWalletFlowDetailCell")
        view.delegate = self
        view.dataSource = self
        return view
    }()
    
    lazy var headerView:  DPWalletFlowDetailHeaderView = {
        let view = DPWalletFlowDetailHeaderView.loadFromXib()
        view.frame = CGRect(x: 0, y: 0, width: UIScreen.width, height: DPWalletFlowDetailHeaderView.height)
        return view
    }()
    
    lazy var bottomView: DPWalletFlowDetailFooterView = {
        let view = DPWalletFlowDetailFooterView.loadFromXib()
        view.frame = CGRect(x: 0, y: 0, width: UIScreen.width, height: UIScreen.showHeight-DPWalletFlowDetailHeaderView.height-50*3)
        return view
    }()
    
    var namesArray: [String] = ["入账时间","交易类型","提现状态","失败原因","交易单号"]
    
    var model: DPWalletFlowItemModel!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.bh_navigationBar.title_label.text = "账单详情"

        self.view.addSubview(self.tableView)
        self.tableView.tableHeaderView = self.headerView
        self.tableView.tableFooterView = self.bottomView
        
        self.headerView.model =  self.model
       
    }
    

}

extension DPWalletFlowDetailViewController: UITableViewDelegate,UITableViewDataSource {
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.namesArray.count
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if self.model.type == 1 {
            if indexPath.row == 2 || indexPath.row == 3 {
                return 0
            }else {
                return 50
            }
        }else {
            if self.model.balanceStatus == 3 { // 提现失败
                return 50
            }else {
                if indexPath.row == 3 {
                    return 0
                }else {
                    return 50
                }
            }
        }
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "DPWalletFlowDetailCell", for: indexPath) as! DPWalletFlowDetailCell
        cell.name_label.text = self.namesArray[indexPath.row]
      
        if indexPath.row == 0 {
            if self.model.type == 1 {
                cell.name_label.text = "入账时间"
            }
            cell.detail_label.text = self.model.date
        }else if indexPath.row == 1 {
            cell.detail_label.text = self.model.type == 1 ? "收入":"支出"
        }else if indexPath.row == 2 {
            cell.detail_label.text = self.model.balanceStateName
        }else if indexPath.row == 3 {
            cell.detail_label.text = self.model.reason
        }else {
            cell.detail_label.text = self.model.alipayNo
        }
        return cell
    }
}
